The CLI

Let’s learn the usage of the command-line interface in clean architecture.

Updating the CLI file#

At this point, fixing the CLI is extremely simple. We need to imitate what we did for the HTTP server, only without considering the filters because they weren’t part of the command-line tool.

cli.py

In line 38, we get the inputs from the URL using the GET method. In line 39, we pass these inputs to build_room_list_request(url_request) to apply the filter on the inputs given in the URL. If we skip line 38, we’ll get all the data.

Apply filters#

By default, our application will show all of the data because it isn’t filtered. After running our application, if we want to filter the data ourselves, we can perform the following steps:

  1. Click the link below the widget.
  2. Append the filter in this filter_attributeName__operation=value pattern to the URL.
Created with Fabric.js 3.6.6
Step 1: Click the URL below the widget

1 of 2

Created with Fabric.js 3.6.6
Step 2: Applying the filter through url

2 of 2

We’ve implemented the filters on the code and price attributes. For code, we can use only the eq operation. For price, we can use all three operations: eq, lt, and gt.

Single filter#

For example, if we want to get all the rooms whose price is less than 50, then we have to append filter_price__lt=50. If we want to get the room whose code is f853578c-fc0f-4e65-81b8-566c5dffa35a, then we have to append filter_code__eq=f853578c-fc0f-4e65-81b8-566c5dffa35a with the URL below the widget containing the project. The slides above explain this in more detail.

Multiple filters#

For multiple filters, we just need to use & to combine our filters. For example, we can use filter_price__gt=30&filter_code__eq=eed76e77-55c1-41ce-985d-ca49bf6c0585 to filter the room whose price is greater than 30 and whose code is eed76e77-55c1-41ce-985d-ca49bf6c0585.

Test the updated code#

In the code editor, we’ve updated the files with the new code.

/
application
rentomatic
requirements
tests
cli.py
pyproject.toml
pytest.ini
requirements.txt
setup.cfg
tox.ini
wsgi.py
Implementing request and responses for filters

Click the “Run” button to open the terminal, and use this command to run the tests:

FLASK_CONFIG="development" flask run -"0.0.0.0"

The output of this code is the unfiltered data on which we can apply filters.

The Repository

Quiz